--a frame is a window that registers its own class.
setfenv(1, require'winapi.oo')
require'winapi.oo.control'
require'winapi.class'
require'winapi.window'

Window = class(Control)

function Window:__init(info)
	info = info or {}
	self.class = RegisterClass{
		name = App.gen_classname(),
		style = info.class_style,
		proc = App.router.proc,
		icon = info.icon,
		small_icon = info.small_icon,
		cursor = info.cursor,
		background = info.background,
	}
	self.window = CreateWindow{
		class = self.class,
		style = info.style,
		style_ex = info.style_ex,
		caption = info.caption,
		x = info.x, y = info.y, w = info.w, h = info.h,
		parent = info.parent,
	}
	self.__state = {
		visible = false,
		is_main = false,
	}
end

function Window:free()
	App.router:remove_control(self.window)
	DestroyWindow(self.window)
	self.window = nil
	UnregisterClass(self.class)
	self.class = nil
end

function Window:set_visible(v)
	ShowWindow(self.window, v and SW_SHOW or SW_HIDE)
end

function Window:set_is_main(v)
	if v then
		App.router:add_handler('Window', self.window, WindowQuitHandler)
	else
		App.router:remove_handler('Window', self.window, WindowQuitHandler)
	end
end

--function Window:set_ self.router:add_handler('Window', self.main_window.window, WindowQuitHandler)end

if not ... then
require'winapi.oo.app'
local window = Window{caption = 'Main', w = 200, h = 200}
local window2 = Window{caption = 'Other', w = 200, h = 200}
window.visible = true
window2.visible = true
window.is_main = true
window.is_main = true
App:run()
end

